package handler

import (
	"github.com/gin-gonic/gin"
	"repo-man/model"
	"strconv"
)

func GoodsList(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size

	var data []model.Goods
	model.DB.Offset(offset).Limit(size).Find(&data)

	var total int64
	model.DB.Model(model.Goods{}).Count(&total)

	c.JSON(200, gin.H{
		"code":  200,
		"msg":   "查询成功",
		"data":  data,
		"total": total,
	})
}
